package DataStuctures.Stack;


import DataStuctures.Array.Array;

import java.util.ArrayList;
import java.util.Arrays;

public class ArrayStack<E> implements Stack<E> {


    //不让用户看到除了栈顶以外的元素
    Array<E> array;


    public ArrayStack(int capacity) {
        array = new Array<>(capacity);
    }

    public ArrayStack(){
        array = new Array<>();
    }



    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public void push(E e) {
        array.addLast(e);
    }

    @Override
    public E pop() {
        return array.removeLast();
    }

    @Override
    public E peek() {
        return array.getLast();
    }


    public int getCapacity(){
        return array.getCapacity();
    }

    @Override
    public String toString(){
        StringBuilder rs = new StringBuilder();
        rs.append("Stack: ");
        rs.append('[');
        for (int i = 0; i < array.getSize(); i++) {
            rs.append(array.get(i));
            if (i != array.getSize()-1) {
                rs.append(", ");
            }
        }
        rs.append("ss] top");
        return rs.toString();
    }
}
